import {mongo} from '#nuxt-mongodb'
import { ObjectId } from 'mongodb';

interface User{
    id: string,
    name: string
}

export default defineEventHandler(async(event:any)=>{
    const {id,name}:User = await readBody(event)
    // console.log(id,name)
    const db = mongo.db()
    const idObj = new ObjectId(id)
    const result =await mongo.db().collection('user').findOne({_id:idObj})
    if(result){
        return {
            status: 200,
            data: result,
            message: "select success"
        }
    }else{
        return {
            status: 404,
            data: result,
            message: "select user not found"
        }
    }
})